package top.quercus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import top.quercus.pojo.User;
import top.quercus.service.UserService;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    //声明业务层属性
    @Autowired
    private UserService userServiceImpl;

    //声明单元方法:处理登录请求
    @RequestMapping("userLogin")
    public String userLogin(String uname, String pwd, HttpServletRequest req) {
        //处理请求
        User user = userServiceImpl.selUserInfoService(uname, pwd);
        //响应结果
        if (user != null) {
            req.getSession().setAttribute("user",user);
            return "redirect:/main.jsp";
        } else {
            req.setAttribute("flag","用户名密码错误！");
            return "/login.jsp";
        }
    }
}
